package javaapplication7;

import java.io.FileReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

public class ConfigImporter11 {

    public static Map<String, String> map = new HashMap<String, String>();
    public static Map<String, String> mapRace = new HashMap<String, String>();
    static Set<String> set = new HashSet<String>();

    public static void main(String[] args) {
        try {
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(new InputSource(new FileReader("hai_voc.xml")));

            doc.getDocumentElement().normalize();

            NodeList nListSystem = doc.getElementsByTagName("system");

            for (int k = 0; k < nListSystem.getLength(); k++) {
                Node nNodeSystem = nListSystem.item(k);
              
                if (nNodeSystem.getNodeType() == Node.ELEMENT_NODE) {

                    Element eElementSystem = (Element) nNodeSystem;

                    NodeList nList = eElementSystem.getElementsByTagName("code");
                    for (int i = 0; i < nList.getLength(); i++) {
                        Node nNode = nList.item(i);
                        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                            Element eElement = (Element) nNode;
                            if ("Race Value Set".equals(eElementSystem.getAttribute("valueSetName"))) {
                                mapRace.put(eElement.getAttribute("value"), eElement.getAttribute("displayName"));
                            } else {
                                map.put(eElementSystem.getAttribute("valueSetOid") + "_" + eElement.getAttribute("value"), eElement.getAttribute("displayName"));
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(map);
        System.out.println(map.size());

        System.out.println(mapRace);
        System.out.println(mapRace.size());
    }
}
